﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using BigfootMVC.Helpers;


namespace BigfootMVC.DNN
{

    /// <summary>
    /// This is the class from which all mvc views need to inherit. It provides
    /// a series of methods and classes that give you easy access to the different helpers throughout the system
    /// It also provides aliased functions like RenderPartial which is part of the JSHelper for easy access.
    /// </summary>
    public class MvcBaseView : UserControl
    {

        /// <summary>
        /// MVC Request Route
        /// </summary>
        public RouteInfo Route { get; set; }

        public DnnApp app { get { return Route.App; } }

        /// <summary>
        /// THIS FIELD IS SET BY THE ROUTE.RENDERPARTIAL TO INDICATE TO THE BASE VIEW THAT IT IS BEING RENDERED BY IT. 
        /// </summary>
        public bool IsRenderPartial;

        /// <summary>
        /// Inclues all view helper functions (i.e. RenderPartial, E, UrlP, Url, Html, JS, TB, Ajax, CreatePartialForm, SubmitPartialForm, RenderIf, Post values, etc.)
        /// </summary>
        public DnnViewHelper BF
        {
            get { return _viewHelper ?? (_viewHelper = new DnnViewHelper(Route, IsRenderPartial)); }
        }
        private DnnViewHelper _viewHelper;

        // These are alias functions from BF used for convinience
        //public DnnApp app { get { return Route.App; } }
        public string uid(string name) {return BF.uid(name);}
        public HtmlHelper Html { get { return BF.Html; } }
        public TagBuilder DIV(string content, string classes) { return BF.DIV(content,classes); }
        public TagBuilder DIV(string content, string classes, params string[] formatValues) { return BF.DIV(content,classes, formatValues); }
        public TagBuilder SPAN(string content, string classes) { return BF.SPAN(content, classes); }
        public TagBuilder SPAN(string content, string classes, params string[] formatValues) { return BF.SPAN(content, classes, formatValues); }
        public JSHelper JS { get { return BF.JS; } }
        public TagBuilder TB(string tagName) { return BF.TB(tagName);  }
        public string E(string value) { return BF.E(value); }
        public string F(string format, params string[] values) { return BF.F(format, values); }
        public AjaxRequest Ajax(string url) { return BF.Ajax(url); }
        public UrlHelper Url { get { return BF.Url; } }
        public string UrlP(string paramName, string value) { return BF.UrlP(paramName, value); }
        public string UrlP(string paramName, int value) { return BF.UrlP(paramName, value); }
        public void HandleViewError(Exception ex){}

        /// <summary>
        /// Retreives the unique route id for this view
        /// </summary>
        public string routeContentId { get { return uid("routeContent"); } }
    }
}

